-- card: 13149 from stack: in.5 -- bmap block id: 13474 -- flags: 0000 -- background id: 3858 -- name: UnmountVolume ----- HyperTalk script ----- on hideObjects hide cd btn "Try It!" end hideObjects on showObjects show cd btn "Try It!" end showObjects -- part 1 (button) -- low flags: 00 -- high flags: A002 -- rect: left=82 top=185 right=219 bottom=175 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 8192 -- line height: 16 -- part name: Try it! ----- HyperTalk script ----- on mouseUp -- umount the specified disk global errGlobal put volumePath() into newVolume if newVolume = empty then exit mouseUp UnmountVolume newVolume, "noDialog:errGlobal" if errGlobal ≠ empty then answer "Error: “" & errGlobal & "”" put empty into errGlobal end if end mouseUp -- part contents for background part 38 ----- text ----- 47/50 -- part contents for background part 20 ----- text ----- An XCMD which Unmounts the specified volume. Calling syntax : UnmountVolume volName, <"noDialog:"errGlobal> VOLNAME: the volume to check. -- part contents for background part 42 ----- text ----- { UnmountDisk(pathname «,“noDialog:”errorGlobal») } { XFCN to unmount the specified volume. } {} { brought to you by: Anup Murarka Eric Carlson } { ALINK: SKEPTIC ALINK: cyNic } { CIS: 76004,3356 } {} { We are part of the Support Tools Development Group, } { Apple Computer, Inc. } {} { please DO NOT contack Mac DTS for support of this code! } {} { please DO contact the authors for support of this code! } {} { Send comments, bug reports, requests to any of the above } { E-mail addresses or to:} {} { (one of us) } { Apple Computer, Inc. } { 900 E. Hamilton, Ave. } { Campbell, CA 95008 } { M/S 72-L } {} { Copyright: © 1989, 1990 by Apple Computer, Inc., all rights reserved. } {} { written by Eric Carlson } { AppleLink: cyNic } { modification history } { Date Initials Comments } { ---- ------ ---------------------------------------------------} { 3/1/90 ec first written } { 6/6/90 ec added additional comments to code } {} unit UnmountDisk; interface uses HyperXCMD; procedure MAIN (paramPtr: XCmdPtr); implementation procedure reportToUser (paramPtr: XCmdPtr; msgStr: str255); {} { report something back to the user. } { the last parameter (optional) to an external may contain } { "noDialog" or "noDialog:GlobalName". GlobalName is the name } { of a HyperTalk global variable into which error messages will be } { placed. we've decided to use this approach to avoid confusing } { an error message with a valid result being returned from an XFCN. } {} var tempStr: str255; begin {check the last param to see if the user requested that} { we suppress the error dialog } ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr); UprString(tempStr, true); if pos('NODIALOG', tempStr) = 0 then { no special error handling specified, throw up a dialog and return the error message } begin SendCardMessage(paramPtr, concat('answer "', msgStr, '"')); paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end else if (pos(':', tempStr) > 0) then { requested global AND noDialog so we fill in the global and return empty } begin tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr)); { get the name of the HC global to fill } SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr)); { and fill it } paramPtr^.returnValue := PasToZero(paramPtr, ''); { return empty } end else { requested noDialog only so we return the error condition as the result } paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end; { procedure } function AskedForHelp (paramPtr: XCmdPtr; syntaxMsg: Str255; copyrightMsg: Str255): boolean; { check to see if the user sent a '?' or a '!' as } { the only parameter. if so we will respond with } { the calling syntax or the copyright/version info } { for this external } {} var firstStr: str255; begin askedForHelp := false; if paramPtr^.paramCount = 1 then begin ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr); { what is the first param? } if firstStr = '?' then begin reportToUser(paramPtr, syntaxMsg); askedForHelp := true end { asked for help } else if firstStr = '!' then begin reportToUser(paramPtr, copyRightMsg); askedForHelp := true end; { asked for copyright info } end; { one parameter passed } end; { function } function NumberToString (paramPtr: XCmdPtr; num: LONGINT): Str255; { use the toolbox call rather than HC's } var tempStr: str255; begin NumToString(num, tempStr); NumberToString := tempStr; end; procedure ReportVolError (paramPtr: XCmdPtr; errorNum: integer); var errMsg, tempName: str255; begin case errorNum of { what caused the problem? } bdNamErr: errMsg := 'Bad volume name.'; extFSErr: errMsg := 'External file system.'; ioErr: errMsg := 'I/O Error.'; nsDrvErr: errMsg := 'No such drive.'; nsvErr: errMsg := 'No such volume.'; paramErr: errMsg := 'No default volume.'; otherwise errMsg := concat('unexpected error #', NumberToString(paramPtr, errorNum)); end; { case } errMsg := concat('Sorry, ', errMsg); reportToUser(paramPtr, errMsg); { return the error message } end; { function } function validVolumeName (volumeName: str255): str255; { a volume name must have one (and only one) colon in it, as } { the last character } begin if pos(':', volumeName) = 0 then validVolumeName := concat(volumeName, ':') else validVolumeName := copy(volumeName, 1, pos(':', volumeName)); end; procedure UnmountDisk (paramPtr: XCmdPtr); var getParamsOK: boolean; volToUnmount: str255; PB: ParamBlockRec; errorCode: OSErr; begin { fetch and validate the passed parameters} if AskedForHelp(paramPtr, 'UnmountVolume volumeName, «“noDialog:”errorGlobal»', '© 1990 Apple Computer, Inc. v.1.1, bu Eric Carlson.') then exit(UnmountDisk); if paramPtr^.paramCount = 0 then begin ReportToUser(paramPtr, 'Volume name expected.'); exit(UnmountDisk); end else ZeroToPas(paramPtr, paramPtr^.Params[1]^, volToUnmount); volToUnmount := validVolumeName(volToUnmount); { make sure the volume name is correct } { initialize parameter block. Since volToUnmount is a full pathname, no other field is needed} zeroBytes(paramPtr, @PB, sizeOf(PB)); PB.ioNamePtr := @volToUnmount; PB.ioVolIndex := -1; errorCode := PBGetVInfo(@PB, false); if errorCode <> noErr then begin ReportVolError(paramPtr, errorCode); exit(UnmountDisk); end; errorCode := PBUnmountVol(@PB); if errorCode <> noErr then ReportVolError(paramPtr, errorCode); exit(UnmountDisk); end; { procedure UnmountDisk} procedure MAIN (paramPtr: XCmdPtr); begin UnmountDisk(paramPtr); end; end. { unit UnmountDisk}